package com.simple.space.modules.shiro.controller;

import com.simple.space.common.constant.Result;
import com.simple.space.modules.base.controller.BaseController;
import com.simple.space.modules.shiro.mapper.UserMapper;
import com.sun.org.apache.regexp.internal.RE;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName AdminController
 * @Author SimpleTree
 **/
@RestController
@RequestMapping("/admin")
public class AdminController extends BaseController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/getUser")
    //@RequiresRoles("admin")
    @RequiresRoles(logical = Logical.OR, value = {"user", "admin"})
    public Result getUser() {
        List<String> list = userMapper.getUser();
        return new Result(200, list);
    }

    /**
     * 封号操作
     */
    @PostMapping("/banUser")
    @RequiresRoles("admin")
    public Result updatePassword(String username) {
        userMapper.banUser(username);
        return new Result(200,"成功");
    }

    @GetMapping("/test")
    public Result test(){
        return new Result(200, "test");
    }
}
